package com.anc.redis.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Data
@Configuration
public class RedissonConfig {
    //@Value("${spring.redis.host}")
    private String host="localhost";
    //@Value("${spring.redis.port}")
    private String port="6379";
    //@Value("${spring.redis.password}")
    private String password="";
    @Bean
    public RedissonClient getRedisSon() {
        Config config = new Config();
        String address = new StringBuilder("redis://").append(host).append(":").append(port).toString();
        //这里使用的是单机的redis，如果是其他方式（主从，哨兵，集群）的话，按照下面的进行修改配置即可
        config.useSingleServer().setAddress(address);
        if (null != password && !"".equals(password.trim())) {
            config.useSingleServer().setPassword(password);
        }
        return Redisson.create(config);
    }

}
